package com.dlu.safe_construction.controller;

import com.dlu.safe_construction.common.ApiResult;
import com.dlu.safe_construction.dto.AreaInfoDTO;
import com.dlu.safe_construction.dto.SpaceInfoDTO;
import com.dlu.safe_construction.model.Space;
import com.dlu.safe_construction.service.SpaceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by  lijiaxing on 2022/3/30 20:24
 *
 * @author lijiaxing
 */
@CrossOrigin
@RestController
@RequestMapping("/space")
@Slf4j
public class SpaceController implements BaseController {
    @Resource
    private SpaceService spaceService;

    @PostMapping(path = "/add.json", produces = APPLICATION_JSON)
    public ApiResult<Void> add(@RequestBody Space space) {
        return spaceService.add(space);
    }

    @PostMapping(path = "/delete.json", produces = APPLICATION_JSON)
    public ApiResult<Void> delete(@RequestBody Space space, @RequestParam Integer byWhat) {
        return spaceService.deleteBy(space, byWhat);
    }

    @PostMapping(path = "/edit.json", produces = APPLICATION_JSON)
    public ApiResult<Void> edit(@RequestBody Space space) {
        return spaceService.edit(space);
    }

    @GetMapping(path = "/list.json", produces = APPLICATION_JSON)
    public ApiResult<List<AreaInfoDTO>> list() {
        return spaceService.listAll();
    }

    @GetMapping(value = "/listBy.json", produces = APPLICATION_JSON)
    public ApiResult<List<SpaceInfoDTO>> listBy(String key, Integer byWhat) {
        return spaceService.searchBy(key, byWhat);
    }
}
